package com.lyf.convert_x.action;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.ui.popup.ListPopup;
import com.lyf.convert_x.enums.DateConverterTypeEnum;
import com.lyf.convert_x.executor.DatePopupExecutor;

import java.util.List;
import java.util.Objects;

public class DateConverterAction extends AnAction {

    @Override
    public void actionPerformed(AnActionEvent e) {
        Editor editor = (Editor) e.getDataContext().getData("editor");
        Project project = e.getProject();
        List<String> typeNameList = DateConverterTypeEnum.getTypeNameList();
        // 创建列表弹出窗口
        ListPopup listPopup = JBPopupFactory.getInstance().createListPopup(new DatePopupExecutor("Date Converter", typeNameList, editor, project));
        // 在屏幕中间显示列表弹出窗口
        listPopup.showCenteredInCurrentWindow(Objects.requireNonNull(e.getProject()));
    }
}
